add internal babl_parse_double; to avoid using atof
authorØyvind Kolås <pippin@gimp.org>
Mon, 9 Jun 2014 00:30:38 +0000 (02:30 +0200)
committerØyvind Kolås <pippin@gimp.org>
Mon, 9 Jun 2014 00:35:14 +0000 (02:35 +0200)
atof is locale dependent; it was being used two places parsing floating point
values from environment variables.

babl/babl-fish-path.c
babl/babl-fish-stats.c
babl/babl-internal.h

index 3b90edf17b54ff949fa6ffd2fe8c895794bad167..5dc06017f5b4b95ab4b0d0dfe3ac39bb9a9c6aeb 100644 (file)
@@ -109,7 +109,7 @@ static double legal_error (void)
 
   env = getenv ("BABL_TOLERANCE");
   if (env && env[0] != '\0')
-    error = atof (env);
+    error = babl_parse_double (env);
   else
     error = BABL_LEGAL_ERROR;
   return error;
index 9c6d52eb3cc62d8fc64ca93185998f2bf73ea0d4..c0b34de47333d728698cdc19f77acb360df2a5fb 100644 (file)
@@ -252,7 +252,7 @@ static double legal_error (void)
 
   env = getenv ("BABL_TOLERANCE");
   if (env && env[0] != '\0')
-    error = atof (env);
+    error = babl_parse_double (env);
   else
     error = BABL_LEGAL_ERROR;
   return error;
index cc05660f9100c693f3ee7b5fc4a87d614d6d8d5e..eb80dd02652987746c9c2c05d4043166361df9dc 100644 (file)
@@ -295,4 +295,26 @@ babl_##klass##_from_id (int id)                               \
 
 #define BABL(obj)  ((Babl*)(obj))
 
+static inline double babl_parse_double (const char *str)
+{
+  double result = 0;
+  if (!str)
+    return 0.0;
+  result = atoi (str);
+  if (strchr (str, '.'))
+  {
+    char *p = strchr (str, '.') + 1;
+    double d = 10;
+    for (;*p && *p > '0' && *p < '9';p++, d *= 10)
+    {
+      if (result >= 0)
+        result += (*p - '0') / d;
+      else
+        result -= (*p - '0') / d;
+    }
+  }
+  return result;
+}
+
+
 #endif